package com.sanben.region.controller;

import com.sanben.common.web.domain.Result;
import com.sanben.region.data.vo.RegionVo;
import com.sanben.region.entity.Region;
import com.sanben.region.service.IRegionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author cyh
 * @description: 城市表 控制器
 * @date: 2020-08-11
 */
@RestController
@RequestMapping("/region")
@Api(tags = "城市表相关接口")
public class RegionController {

    @Autowired
    private IRegionService iRegionService;

    @GetMapping("/home/hotList")
    @ApiOperation(value = "首页-热门城市列表")
    public Result<List<Region>> getHomeHotList() {
        List<Region> list = iRegionService.getHomeHotList();
        return Result.data(list);
    }

    @PostMapping("/home/list")
    @ApiOperation(value = "首页-城市列表")
    public Result<RegionVo> getHomeList() {
        return Result.data(iRegionService.getHomeList());
    }

    @GetMapping("/{code}")
    @ApiOperation(value = "根据code查询城市信息")
    public Result<Region> detail(@PathVariable @NotNull(message = "城市code不能为空") Integer code) {
        return Result.data(iRegionService.detail(code));
    }

}
